package com.deschen.security.core.authentication;

import com.deschen.security.core.properties.SecurityConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

/**
 * @Author deschen
 * @Create 2019/8/24
 * @Description 安全公共配置类
 * @Since 1.0.0
 */
public class AbstractChannelSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private AuthenticationSuccessHandler customAuthenticationSuccessHandler;

    @Autowired
    private AuthenticationFailureHandler customAuthenticationFailureHandler;



    protected void applyPasswordAuthenticationConfig(HttpSecurity http) throws Exception {
        http.formLogin() // 登入页面
                .loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL)  //登入页面请求
                // 用于提交登入信息，被UsernamePasswordAuthenticationFilter认证
                .loginProcessingUrl(SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_FORM)
                // 认证成功处理
                .successHandler(customAuthenticationSuccessHandler)
                // 认证失败处理
                .failureHandler(customAuthenticationFailureHandler);



    }
}
